<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@taglib prefix="s" uri="/struts-tags"  %>
<%
	String operation = request.getParameter("operation");
%>
<%@ page import="com.starbaba.core.web.constant.WebConstants"%>
<%@ page import="com.starbaba.system.user.model.UserVO"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
.table>th {
	vertical-align: center;
	background-color: grey;
}
input[type="radio"] {
   font-size: 100px;
   vertical-align:middle;
   margin-top:-2px; 
   margin-left:2px;
   margin-bottom:1px;
}
</style>
</head>
<body class="no-skin">
	<div class="page-content">
		<div class="page-content-area">
			<div class="row">
				<div class="col-xs-12 col-sm-12 widget-container-col">
					<div class="widget-box widget-color-blue">
						<!-- #section:custom/widget-box.options.collapsed -->
						<div class="widget-header widget-header-small">
							<h6 class="widget-title lighter">
								<i class="ace-icon glyphicon glyphicon-th-list"></i>编辑商品
							</h6>
							<div class="widget-toolbar no-border">
								<a href="#" data-action="collapse"> <i
									class="ace-icon fa fa-chevron-up"></i>
								</a>
							</div>
						</div>

						<div class="widget-body">
							<div class="widget-main">
								<form class="form-horizontal" id="product-form"
									name="product-form" method="post" enctype="multipart/form-data">
									<input type="hidden" name="user_name" id="user_name" value="<%=((UserVO) session.getAttribute(WebConstants.SESSION_ATTRIBUTE_USER)).getUsername() %>"/>
									<input type="hidden" name="id" id="id" value="${paramsMap.mallItem.id}"/>
									
									<table id="baseinfo" class="table table-bordered table-striped table-hover table-condensed table-responsive table">
										<tbody id="optionTable">
	                                        <tr>
												<td>商品标题</td>
												<td><input type="text" name="title" id="title" value="${paramsMap.mallItem.title}" placeholder="" class="col-xs-12 col-sm-12"/></td>
											</tr>
											<tr>
												<td>商品类型</td>
												<td>
													<select name="is_coupon_item" class="col-xs-12 col-sm-12">
														<option value="0" <c:if test="${paramsMap.mallItem.is_coupon_item eq '0'}">selected="selected"</c:if>>返利商品</option>
														<option value="1" <c:if test="${paramsMap.mallItem.is_coupon_item eq '1'}">selected="selected"</c:if>>领券商品</option>
													</select>
												</td>
											</tr>
											<tr>
												<td>一句话描述</td>
												<td><input type="text" name="a_word_desc" id="a_word_desc" value="${paramsMap.mallItem.a_word_desc}" placeholder="" class="col-xs-12 col-sm-12"/></td>
											</tr>
											<tr>
												<td>优惠券详情</td>
												<td><input type="text" disabled="disabled" name="coupon_info" id="coupon_info" value="${paramsMap.mallItem.coupon_info}" placeholder="" class="col-xs-12 col-sm-12"/></td>
											</tr>
											<tr>
												<td>介绍专题商品详情</td>
												<td><input type="text" name="introduction_topic_details" id="introduction_topic_details" value="${paramsMap.mallItem.introduction_topic_details}" placeholder="" class="col-xs-12 col-sm-12"/></td>
											</tr>
											<tr>
												<td>返利金额</td>
												<td><input type="text" name="fanli_amout" id="fanli_amout" value="${paramsMap.mallItem.fanli_amout}" placeholder="" class="col-xs-12 col-sm-12"/></td>
											</tr>
											<tr>
												<td>商品标签</td>
												<td><input type="text" name="tag_name" id="tag_name" value="${paramsMap.mallItem.tag_name}" placeholder="" class="col-xs-12 col-sm-12"/></td>
											</tr>
											<tr>
												<td>收入比例</td>
												<td>
												<input type="text" name="tk_rate" id="tk_rate" value="${paramsMap.mallItem.tk_rate}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>商品主图</td>
												<td>
												<img id="mainImg" src="${paramsMap.mallItem.img}" width="150px;" height="150px;" 
													onerror="javascript:this.src='http://img.xmiles.cn/img/void.png'"
													style="border:1px solid #C7C7C7;">
												<input type="file" id="mainImgFile" name="mainImgFile" value="${paramsMap.mallItem.img}">
												</td>
											</tr>
											<tr>
												<td>商品小图列表</td>
												<td>
												<c:forEach items="${paramsMap.smallImgList}" var="item">
													<img src="${item}" width="120px;" height="120px;" 
														onerror="javascript:this.src='http://img.xmiles.cn/img/void.png'"
														style="border:1px solid #C7C7C7;">
												</c:forEach>
												</td>
											</tr>
											<tr>
												<td>介绍专题主图</td>
												<td>
												<img id="introductionTopicImg" src="${paramsMap.mallItem.introduction_topic_img}" width="150px;" height="150px;" 
													onerror="javascript:this.src='http://img.xmiles.cn/img/void.png'"
													style="border:1px solid #C7C7C7;">
												<input type="file" id="introductionTopicImgFile" name="introductionTopicImgFile" value="${paramsMap.mallItem.img}">
												</td>
											</tr>
											<tr>
												<td>商品一口价格</td>
												<td>
													<input  disabled="disabled" type="text" name="reserve_price" id="reserve_price" value="${paramsMap.mallItem.reserve_price}" placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>商品折扣价格</td>
												<td>
												<input  disabled="disabled" type="text" name="zk_final_price" id="zk_final_price" value="${paramsMap.mallItem.final_price}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>卖家类型</td>
												<td>
												<c:choose>
												<c:when test="${paramsMap.sourceData.user_type eq '0'}">
													<input  disabled="disabled" type="text" name="user_type" id="user_type" value="集市" 
														placeholder="" class="col-xs-12 col-sm-12"/>
												</c:when>
												<c:otherwise>
													<input  disabled="disabled" type="text" name="img" id="img" value="商城" 
														placeholder="" class="col-xs-12 col-sm-12"/>
												</c:otherwise>
												</c:choose>
												</td>
											</tr>
											<tr>
												<td>宝贝所在地</td>
												<td>
												<input  disabled="disabled" type="text" name="provcity" id="provcity" value="${paramsMap.sourceData.provcity}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>商品地址</td>
												<td>
												<input  disabled="disabled" type="text" name="item_url" id="item_url" value="${paramsMap.sourceData.item_url}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>淘客地址</td>
												<td>
												<input  disabled="disabled" type="text" name="click_url" id="click_url" value="${paramsMap.sourceData.click_url}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>30天销量</td>
												<td>
												<input  disabled="disabled" type="text" name="volume" id="volume" value="${paramsMap.sourceData.volume}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>无线折扣价</td>
												<td>
												<input  disabled="disabled" type="text" name="zk_final_price_wap" id="zk_final_price_wap" value="${paramsMap.sourceData.zk_final_price_wap}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>上线时间</td>
												<td>
												<input  disabled="disabled" type="text" name="event_start_time" id="event_start_time" value="${paramsMap.sourceData.event_start_time}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>下线时间</td>
												<td>
												<input  disabled="disabled" type="text" name="event_end_time" id="event_end_time" value="${paramsMap.sourceData.event_end_time}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>宝贝类型</td>
												<td>
												<c:if test="${paramsMap.sourceData.type eq '1'}">
													<input  disabled="disabled" type="text" name="type" id="type" value="普通商品" 
														placeholder="" class="col-xs-12 col-sm-12"/>
												</c:if>
												<c:if test="${paramsMap.sourceData.type eq '2'}">
													<input  disabled="disabled" type="text" name="type" id="type" value="鹊桥高佣金商品" 
														placeholder="" class="col-xs-12 col-sm-12"/>
												</c:if>
												<c:if test="${paramsMap.sourceData.type eq '3'}">
													<input  disabled="disabled" type="text" name="type" id="type" value="定向招商商品" 
														placeholder="" class="col-xs-12 col-sm-12"/>
												</c:if>
												<c:if test="${paramsMap.sourceData.type eq '4'}">
													<input  disabled="disabled" type="text" name="type" id="type" value="营销计划商品" 
														placeholder="" class="col-xs-12 col-sm-12"/>
												</c:if>
												</td>
											</tr>
											<tr>
												<td>联盟宝贝状态</td>
												<td>
												<c:if test="${paramsMap.mallItem.source_status eq '0'}">
													<input  disabled="disabled" type="text" name="status" id="status" value="失效" 
														placeholder="" class="col-xs-12 col-sm-12"/>
												</c:if>
												<c:if test="${paramsMap.mallItem.source_status eq '1'}">
													<input  disabled="disabled" type="text" name="status" id="status" value="有效" 
														placeholder="" class="col-xs-12 col-sm-12"/>
												</c:if>
												</td>
											</tr>
											<tr>
												<td>后台一级类目</td>
												<td>
												<input  disabled="disabled" type="text" name="category" id="category" value="${paramsMap.sourceData.category}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>优惠券推广链接</td>
												<td>
												<input  disabled="disabled" type="text" name="coupon_click_url" id="coupon_click_url" value="${paramsMap.sourceData.coupon_click_url}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>优惠券结束时间</td>
												<td>
												<input  disabled="disabled" type="text" name="coupon_end_time" id="coupon_end_time" value="${paramsMap.sourceData.coupon_end_time}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>优惠券面额</td>
												<td>
												<input  disabled="disabled" type="text" name="coupon_info" id="coupon_info" value="${paramsMap.sourceData.coupon_info}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>优惠券开始时间</td>
												<td>
												<input  disabled="disabled" type="text" name="coupon_start_time" id="coupon_start_time" value="${paramsMap.sourceData.coupon_start_time}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>优惠券总量</td>
												<td>
												<input  disabled="disabled" type="text" name="coupon_total_count" id="coupon_total_count" value="${paramsMap.sourceData.coupon_total_count}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
											<tr>
												<td>优惠券剩余量</td>
												<td>
												<input  disabled="disabled" type="text" name="coupon_remain_count" id="coupon_remain_count" value="${paramsMap.sourceData.coupon_remain_count}" 
													placeholder="" class="col-xs-12 col-sm-12"/>
												</td>
											</tr>
										</tbody>
									</table>
									
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn  btn-inverse  no-border " onclick="doCancle()"
						id="delete">
						<i class="ace-icon fa fa-undo bigger-160"></i> 取消
					</button>
					&nbsp; &nbsp; &nbsp;
					<button id="btn-save" name="btn-save"
						class="btn  btn-success  no-border" type="button"
						onclick="doSave()">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 保存
					</button>
				</div>
			</div>
		</div>
	</div>

	<%@ include file="/common/common-js.jsp"%>
	<%@ include file="/discovery/maxlength.jsp"%>
	<script type="text/javascript" src="${ctx}/ace/js/maxlength.js"></script>
	<script type="text/javascript" src="${ctx}/js/wangEditor-1.3.11.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery.form.js"></script>
	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
	<script>
		var $multiple = 1;
		var $selector = '';
		var $input = '';

		$(function() {
			$('#mainImgFile').change(function() {
				var file = this.files[0];
				var r = new FileReader();
				r.readAsDataURL(file);
				$(r).load(function() {
					$('#mainImg').attr('src', this.result);
					$('#mainImgFile').attr("value", this.result);
				});
			});
			
			$('#introductionTopicImgFile').change(function() {
				var file = this.files[0];
				var r = new FileReader();
				r.readAsDataURL(file);
				$(r).load(function() {
					$('#introductionTopicImg').attr('src', this.result);
					$('#introductionTopicImgFile').attr("value", this.result);
				});
			});

			//点击按钮
			$('.get-img-modal').on('click', function() {
				//展示模态框
				var $this = $(this);
				var $title = $this.attr('data-title');
				$input = $this.attr('data-input');
				$selector = $this.attr('data-selector');
				$multiple = $this.attr('data-multiple');
				if ($multiple == 1) {
					$('input[name="myFile"]').prop('multiple', true);
				} else {
					$('input[name="myFile"]').prop('multiple', false);
				}
				$('#Modal').find('h4.modal-title').html($title);
				$('#Modal').modal('show');
				return false;
			});

			$('.thumbnail').on('click', function() {
				$('#thumbnail').attr('src', "");
				$("input[id=thumbnail]").val("");
			});

		});

		function doCancle() {
			try {
				if (parent) {
					parent.parent['__extdialog_active'].dialog('close');
				}
			} catch (e) {
				window.history.back();
			}
		}

		function doSave() {
			if(isBlock($("#title").val())){
				parent.bootbox.alert("商品标题不能为空");
				return;
			}
			/* var mainImgFile = $("#mainImgFile").val();
			if(isBlock(mainImgFile)){
				parent.bootbox.alert("商品主图不能为空");
				return;
			} */
			saveForm();
		}

		function saveForm() {
			var saveUrl = ctx + "/mallItem/saveItem.action";
			var options = {
				url : saveUrl,
				type : "POST",
				dataType : "json",
				beforeSend : function() {
					$(".load_bg,.load_img").show();
				},
				success : function(data) {
					parent.parent['__extdialog_active'].dialog('close');
					parent.query_any();
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert(textStatus);
					console.log(XMLHttpRequest, textStatus, errorThrown);
				},
				complete : function() {
					$(".load_bg,.load_img").hide();
				}
			};
			$('form[name="product-form"]').ajaxSubmit(options);
		}
		
		function isBlock(value){
			if(value==""||value==null||value==undefined){
				return true;
			}
			return false;
		}
	</script>
</body>
</html>
